package net.wantongtech.xa.uploadbasicinfo.dao;

import com.wtkj.dao.impl.BaseDataTemplate;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 纠正错误的清分数据类型DAO实现
 *
 * @author MaShibo
 * 日期 :  2020/2/5
 */
@Repository
public class CorrectErrorClearingFileTypeDao extends BaseDataTemplate {

    /**
     * D5013CC9-E08D-6F92-D128-076545EE826B
     * @return 接收表ID集合
     */
    public List<String> queryCorrectingErrorReceiveId() {
        final String sql =
                "SELECT a.listid\n" +
                        "  FROM tq_interactionorgmsgreceive a\n" +
                        "  LEFT JOIN tq_interactionorgmsgerror e\n" +
                        "    ON a.listid = e.receivelistid\n" +
                        " WHERE a.bizcode = 61011014\n" +
                        "   AND a.state = 2\n" +
                        "   AND a.conmsgid = 20200122\n" +
                        " ORDER BY a.conmsgid, a.createon DESC";
        return jdbcTemplate.queryForList(sql, String.class);
    }


    public Integer queryTargetTransType(String tollProvinceId, String issuerId, Long messageId) {
        final String sql =
                "SELECT tr.type\n" +
                        "  FROM tr_portal_transout tr\n" +
                        " WHERE tr.tollprovinceid = ?\n" +
                        "   AND tr.issuerid = ?\n" +
                        "   AND tr.messageid = ?";
        return jdbcTemplate.query(sql, rs -> {
            if (rs.next()) {
                return (Integer) JdbcUtils.getResultSetValue(rs, 1, Integer.class);
            }
            return null;
        }, tollProvinceId, issuerId, messageId);
    }

}
